#! /bin/bash

source $HOME/.plait/config
export S3DIR="/mnt/s3/music"
export BASEURL=http://$AWS_S3_BUCKET.s3.amazonaws.com/music

echo "PLATFORM=any-s3" > $HOME/.plait/s3-config
echo "MUSICDIR=$S3DIR" >> $HOME/.plait/s3-config
echo "BASEURL=$BASEURL" >> $HOME/.plait/s3-config

echo Building local play list...
plait > /dev/null --platform any-listonly "$@" 

echo Syncing music files to S3...
awk -f $INSTALLDIR/share/plait/treecopy.awk d="$MUSICDIR/" to="$S3DIR/" "$HOME/.plait/playlist.m3u" | sort -u | sh

echo Building remote play list...
plait --guest s3 --cache
plait --guest s3 "$@"
